package com.jiecao.news.jiecaonews.util.view;


import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.os.Looper;
import android.os.MessageQueue;
import android.widget.ImageView;

import com.jiecao.news.jiecaonews.R;


public class LoaingBar {

	Dialog dialog;
	private ImageView iv;
	private AnimationDrawable animation;
	public LoaingBar(Context context) {
		dialog = new Dialog(context, R.style.newdialog);
		dialog.setContentView(R.layout.loading_bar_layout);
		iv = (ImageView) dialog.findViewById(R.id.animationIV);
		animation = (AnimationDrawable) iv.getDrawable();  
	}
	public void show() {
		dialog.show();
		dialog.setCanceledOnTouchOutside(false);
		Looper.myQueue().addIdleHandler(new MessageQueue.IdleHandler() {  
		    public boolean queueIdle() {  
		    	animation.start();  
		        return false;  //执行后把当前handler对象从消息队列中移除  
		    }  
		});
	}

	public void hide() {
		iv.clearAnimation();
		dialog.hide();
	}

	public void dismiss() {
		iv.clearAnimation();
		dialog.dismiss();
	}
	

}
